home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / LabelView.java < prev    next >
Text File  |  1998-06-30  |  24KB  |  714 lines

  1. /*
  2.  * @(#)LabelView.java    1.38 98/04/09
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package com.sun.java.swing.text;
  21.  
  22. import java.awt.*;
  23. import com.sun.java.swing.event.*;
  24.  
  25. /**
  26.  * A LabelView is a styled chunk of text that represents a view
  27.  * mapped over an element in the text model.  The view supports breaking
  28.  * for the purpose of formatting.   The fragments produced
  29.  * by breaking share the view that has primary responsibility
  30.  * for the element (i.e. they are nested classes and carry only 
  31.  * a small amount of state of their own) so they can share its 
  32.  * resources.
  33.  * <p>
  34.  * This view is generally responsible for displaying character
  35.  * level attributes in some way.  Since this view represents 
  36.  * text that may have tabs embedded in it, it implements the
  37.  * <code>TabableView</code> interface.  Tabs will only be
  38.  * expanded if this view is embedded in a container that does
  39.  * tab expansion.  ParagraphView is an example of a container
  40.  * that does tab expansion.
  41.  *
  42.  * @author Timothy Prinzing
  43.  * @version 1.38 04/09/98
  44.  */
  45. public class LabelView extends View implements TabableView {
  46.  
  47.     /**
  48.      * Constructs a new view wrapped on an element.
  49.      *
  50.      * @param elem the element
  51.      */
  52.     public LabelView(Element elem) {
  53.     super(elem);
  54.     text = new Segment();
  55.     }
  56.  
  57.     /**
  58.      * Load the text buffer with the given range
  59.      * of text.  This is used by the fragments 
  60.      * broken off of this view as well as this 
  61.      * view itself.
  62.      */
  63.     final void loadText(int p0, int p1) {
  64.     try {
  65.         Document doc = getDocument();
  66.         doc.getText(p0, p1 - p0, text);
  67.         if (rightToLeft) {
  68.         // PENDING(Java2D) use real rendering with shaping
  69.         char[] reversed = new char[p1 - p0];
  70.         int i = 0;
  71.         for (int offs = text.offset + text.count - 1; offs >= text.offset; offs--) {
  72.             reversed[i++] = text.array[offs];
  73.         }
  74.         text.array = reversed;
  75.         text.offset = 0;
  76.         }
  77.     } catch (BadLocationException bl) {
  78.         throw new StateInvariantError("LabelView: Stale view: " + bl);
  79.     }
  80.     }
  81.  
  82.     /**
  83.      * Paint the given range.  This is used by the
  84.      * fragments broken off of this view as well as this
  85.      * view itself.
  86.      */
  87.     final void paintText(Graphics g, Shape a, int p0, int p1, boolean stripWhitespace) {
  88.     Rectangle alloc = a.getBounds();
  89.     sync();
  90.     loadText(p0, p1);
  91.     int y = alloc.y + alloc.height - metrics.getDescent();
  92.     g.setFont(font);
  93.     g.setColor(fg);
  94.     Utilities.drawTabbedText(text, alloc.x, y, g, expander, p0);
  95.     if (underline) {
  96.         if (stripWhitespace) {
  97.         while ((text.count > 0) && (Character.isWhitespace(text.array[text.count-1]))) {
  98.             alloc.width -= metrics.charWidth(text.array[text.count-1]);
  99.             text.count -= 1;
  100.         }
  101.         }
  102.         y += 1;
  103.         g.drawLine(alloc.x, y, alloc.x + alloc.width, y);
  104.     }
  105.     }
  106.  
  107.     /**
  108.      * Synchronize the view's cached values with the model.
  109.      * This causes the font, metrics, color, etc to be 
  110.      * recached if the cache has been invalidated.
  111.      */
  112.     final void sync() {
  113.     if (font == null) {
  114.         Element e = getElement();
  115.         Document d = getDocument();
  116.         if (d instanceof StyledDocument) {
  117.         StyledDocument doc = (StyledDocument) d;
  118.         AttributeSet attr = e.getAttributes();
  119.         font = doc.getFont(attr);
  120.         fg = doc.getForeground(attr);
  121.         underline = StyleConstants.isUnderline(attr);
  122.         metrics = Toolkit.getDefaultToolkit().getFontMetrics(font);
  123.         } else {
  124.         throw new StateInvariantError("LabelView needs StyledDocument");
  125.         }
  126.     }
  127.     }
  128.  
  129.     /**
  130.      * Determines the preferred span for this view along an
  131.      * axis. This is shared by the broken views.
  132.      *
  133.      * @param axis may be either X_AXIS or Y_AXIS
  134.      * @param x the location to calculate the span from.
  135.      * @returns  the span the view would like to be rendered into.
  136.      *           Typically the view is told to render into the span
  137.      *           that is returned, although there is no guarantee.  
  138.      *           The parent may choose to resize or break the view.
  139.      */
  140.     final float getPreferredSpan(int axis, int p0, int p1, int x) {
  141.     sync();
  142.     switch (axis) {
  143.     case View.X_AXIS:
  144.         loadText(p0, p1);
  145.         int width = Utilities.getTabbedTextWidth(text, metrics, x, expander, p0);
  146.         return Math.max(width, 1);
  147.     case View.Y_AXIS:
  148.         return metrics.getHeight();
  149.     default:
  150.         throw new IllegalArgumentException("Invalid axis: " + axis);
  151.     }
  152.     }
  153.  
  154.     /**
  155.      * Provides a mapping from the document model coordinate space
  156.      * to the coordinate space of the view mapped to it.
  157.      * This is shared by the broken views.
  158.      *
  159.      * @param pos the position to convert
  160.      * @param a the allocated region to render into
  161.      * @return the bounding box of the given position
  162.      * @exception BadLocationException  if the given position does not represent a
  163.      *   valid location in the associated document
  164.      * @see View#modelToView
  165.      */
  166.     Shape modelToView(int pos, Shape a, int p0, int p1) throws BadLocationException {
  167.     Rectangle alloc = a.getBounds();
  168.     if ((pos >= p0) && (pos <= p1)) {
  169.         // determine range to the left of the position
  170.         loadText(p0, pos);
  171.         sync();
  172.         int width = Utilities.getTabbedTextWidth(text, metrics, alloc.x, expander, p0);
  173.         if (rightToLeft) {
  174.         // PENDING(Java2D) use real rendering with shaping
  175.         return new Rectangle(alloc.x + alloc.width - width, 
  176.                      alloc.y, 0, metrics.getHeight());
  177.         }
  178.         return new Rectangle(alloc.x + width, alloc.y, 0, metrics.getHeight());
  179.     }
  180.     throw new BadLocationException("modelToView - can't convert", p1);
  181.     }
  182.  
  183.     /**
  184.      * Provides a mapping from the view coordinate space to the logical
  185.      * coordinate space of the model.
  186.      *
  187.      * @param x the X coordinate
  188.      * @param y the Y coordinate
  189.      * @param a the allocated region to render into
  190.      * @return the location within the model that best represents the
  191.      *  given point of view
  192.      * @see View#viewToModel
  193.      */
  194.     int viewToModel(float x, float y, Shape a, int p0, int p1) {
  195.     Rectangle alloc = a.getBounds();
  196.     sync();
  197.     loadText(p0, p1);
  198.     int offs = Utilities.getTabbedTextOffset(text, metrics, 
  199.                          alloc.x, (int) x, expander, p0);
  200.     if (rightToLeft) {
  201.         // PENDING(Java2D) use real rendering with shaping
  202.         return p1 - offs;
  203.     }
  204.     return p0 + offs;
  205.     }
  206.  
  207.     int getBreakWeight(int axis, float pos, float len, int p0, int p1) {
  208.     if (axis == View.X_AXIS) {
  209.         sync();
  210.         loadText(p0, p1);
  211.         int index = Utilities.getTabbedTextOffset(text, metrics, 
  212.                               (int)pos, (int)(pos+len), 
  213.                               expander, p0);
  214.         if (index == 0) {
  215.         // break is at the start offset
  216.         return BadBreakWeight;
  217.         }
  218.         for (int i = text.offset + Math.min(index, text.count - 1); 
  219.          i >= text.offset; i--) {
  220.  
  221.         char ch = text.array[i];
  222.         if (Character.isWhitespace(ch)) {
  223.             // found whitespace
  224.             return ExcellentBreakWeight;
  225.         }
  226.         }
  227.         // no whitespace
  228.         return GoodBreakWeight;
  229.     }
  230.     return super.getBreakWeight(axis, pos, len);
  231.     }
  232.  
  233.     // --- TabableView methods --------------------------------------
  234.  
  235.     /**
  236.      * Determines the desired span when using the given 
  237.      * tab expansion implementation.  
  238.      *
  239.      * @param x the position the view would be located
  240.      *  at for the purpose of tab expansion >= 0.
  241.      * @param e how to expand the tabs when encountered.
  242.      * @return the desired span >= 0
  243.      * @see TabableView#getTabbedSpan
  244.      */
  245.     public float getTabbedSpan(float x, TabExpander e) {
  246.     expander = e;
  247.     this.x = (int) x;
  248.     return getPreferredSpan(X_AXIS, getStartOffset(), getEndOffset(), this.x);
  249.     }
  250.     
  251.     /**
  252.      * Determines the span along the same axis as tab 
  253.      * expansion for a portion of the view.  This is
  254.      * intended for use by the TabExpander for cases
  255.      * where the tab expansion involves aligning the
  256.      * portion of text that doesn't have whitespace 
  257.      * relative to the tab stop.  There is therefore
  258.      * an assumption that the range given does not
  259.      * contain tabs.
  260.      * <p>
  261.      * This method can be called while servicing the
  262.      * getTabbedSpan or getPreferredSize.  It has to
  263.      * arrange for its own text buffer to make the
  264.      * measurements.
  265.      *
  266.      * @param p0 the starting document offset >= 0
  267.      * @param p1 the ending document offset >= p0
  268.      * @return the span >= 0
  269.      */
  270.     public float getPartialSpan(int p0, int p1) {
  271.     // PENDING should probably use a static buffer since there 
  272.     // should be only one thread accessing it.
  273.     sync();
  274.     int width = 0;
  275.     try {
  276.         Segment s = new Segment();
  277.         getDocument().getText(p0, p1 - p0, s);
  278.         width = Utilities.getTabbedTextWidth(s, metrics, x, expander, p0);
  279.     } catch (BadLocationException bl) {
  280.     }
  281.     return width;
  282.     }
  283.  
  284.     // --- View methods ---------------------------------------------
  285.  
  286.     /**
  287.      * Renders a portion of a text style run.
  288.      *
  289.      * @param g the rendering surface to use
  290.      * @param a the allocated region to render into
  291.      */
  292.     public void paint(Graphics g, Shape a) {
  293.     paintText(g, a, getStartOffset(), getEndOffset(), false);
  294.     }
  295.  
  296.     /**
  297.      * Determines the preferred span for this view along an
  298.      * axis. 
  299.      *
  300.      * @param axis may be either View.X_AXIS or View.Y_AXIS
  301.      * @returns  the span the view would like to be rendered into >= 0.
  302.      *           Typically the view is told to render into the span
  303.      *           that is returned, although there is no guarantee.  
  304.      *           The parent may choose to resize or break the view.
  305.      */
  306.     public float getPreferredSpan(int axis) {
  307.     return getPreferredSpan(axis, getStartOffset(), getEndOffset(), this.x);
  308.     }
  309.  
  310.     /**
  311.      * Determines the desired alignment for this view along an
  312.      * axis.  For the label, the alignment is along the font
  313.      * baseline for the y axis, and the superclasses alignment
  314.      * along the x axis.
  315.      *
  316.      * @param axis may be either View.X_AXIS or View.Y_AXIS
  317.      * @returns the desired alignment.  This should be a value
  318.      *   between 0.0 and 1.0 inclusive, where 0 indicates alignment at the
  319.      *   origin and 1.0 indicates alignment to the full span
  320.      *   away from the origin.  An alignment of 0.5 would be the
  321.      *   center of the view.
  322.      */
  323.     public float getAlignment(int axis) {
  324.     if (axis == View.Y_AXIS) {
  325.         float h = metrics.getHeight();
  326.         float d = metrics.getDescent();
  327.         float align = (h - d) / h;
  328.         return align;
  329.     } 
  330.     return super.getAlignment(axis);
  331.     }
  332.  
  333.  
  334.     /**
  335.      * Provides a mapping from the document model coordinate space
  336.      * to the coordinate space of the view mapped to it.
  337.      *
  338.      * @param pos the position to convert >= 0
  339.      * @param a the allocated region to render into
  340.      * @return the bounding box of the given position
  341.      * @exception BadLocationException  if the given position does not represent a
  342.      *   valid location in the associated document
  343.      * @see View#modelToView
  344.      */
  345.     public Shape modelToView(int pos, Shape a) throws BadLocationException {
  346.     return modelToView(pos, a, getStartOffset(), getEndOffset());
  347.     }
  348.  
  349.     /**
  350.      * Provides a mapping from the view coordinate space to the logical
  351.      * coordinate space of the model.
  352.      *
  353.      * @param x the X coordinate >= 0
  354.      * @param y the Y coordinate >= 0
  355.      * @param a the allocated region to render into
  356.      * @return the location within the model that best represents the
  357.      *  given point of view >= 0
  358.      * @see View#viewToModel
  359.      */
  360.     public int viewToModel(float x, float y, Shape a) {
  361.     return viewToModel(x, y, a, getStartOffset(), getEndOffset());
  362.     }
  363.  
  364.     /**
  365.      * Gives notification from the document that attributes were changed
  366.      * in a location that this view is responsible for.
  367.      *
  368.      * @param e the change information from the associated document
  369.      * @param a the current allocation of the view
  370.      * @param f the factory to use to rebuild if the view has children
  371.      * @see View#changedUpdate
  372.      */
  373.     public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
  374.     font = null;
  375.     }
  376.  
  377.     /**
  378.      * Determines how attractive a break opportunity in 
  379.      * this view is.  This can be used for determining which
  380.      * view is the most attractive to call <code>breakView</code>
  381.      * on in the process of formatting.  The
  382.      * higher the weight, the more attractive the break.  A
  383.      * value equal to or lower than <code>View.BadBreakWeight</code>
  384.      * should not be considered for a break.  A value greater
  385.      * than or equal to <code>View.ForcedBreakWeight</code> should
  386.      * be broken.
  387.      * <p>
  388.      * This is implemented to forward to the superclass for 
  389.      * the Y_AXIS.  Along the X_AXIS the following values
  390.      * may be returned.
  391.      * <dl>
  392.      * <dt><b>View.ExcellentBreakWeight</b>
  393.      * <dd>if there is whitespace proceeding the desired break 
  394.      *   location.  
  395.      * <dt><b>View.BadBreakWeight</b>
  396.      * <dd>if the desired break location results in a break
  397.      *   location of the starting offset.
  398.      * <dt><b>View.GoodBreakWeight</b>
  399.      * <dd>if the other conditions don't occur.
  400.      * </dl>
  401.      * This will normally result in the behavior of breaking
  402.      * on a whitespace location if one can be found, otherwise
  403.      * breaking between characters.
  404.      *
  405.      * @param axis may be either View.X_AXIS or View.Y_AXIS
  406.      * @param pos the potential location of the start of the 
  407.      *   broken view >= 0.  This may be useful for calculating tab
  408.      *   positions.
  409.      * @param len specifies the relative length from <em>pos</em>
  410.      *   where a potential break is desired >= 0.
  411.      * @return the weight, which should be a value between
  412.      *   View.ForcedBreakWeight and View.BadBreakWeight.
  413.      * @see LabelView
  414.      * @see ParagraphView
  415.      * @see BadBreakWeight
  416.      * @see GoodBreakWeight
  417.      * @see ExcellentBreakWeight
  418.      * @see ForcedBreakWeight
  419.      */
  420.     public int getBreakWeight(int axis, float pos, float len) {
  421.     return getBreakWeight(axis, pos, len, getStartOffset(), getEndOffset());
  422.     }
  423.  
  424.     /**
  425.      * Breaks this view on the given axis at the given length.
  426.      * This is implemented to attempt to break on a whitespace
  427.      * location, and returns a fragment with the whitespace at
  428.      * the end.  If a whitespace location can't be found, the
  429.      * nearest character is used.
  430.      *
  431.      * @param axis may be either View.X_AXIS or View.Y_AXIS
  432.      * @param p0 the location in the model where the
  433.      *  fragment should start it's representation >= 0.
  434.      * @param pos the position along the axis that the
  435.      *  broken view would occupy >= 0.  This may be useful for
  436.      *  things like tab calculations.
  437.      * @param len specifies the distance along the axis
  438.      *  where a potential break is desired >= 0.  
  439.      * @return the fragment of the view that represents the
  440.      *  given span, if the view can be broken.  If the view
  441.      *  doesn't support breaking behavior, the view itself is
  442.      *  returned.
  443.      * @see View#breakView
  444.      */
  445.     public View breakView(int axis, int p0, float pos, float len) {
  446.     if (axis == View.X_AXIS) {
  447.         sync();
  448.         loadText(p0, getEndOffset());
  449.         int index = Utilities.getTabbedTextOffset(text, metrics, 
  450.                               (int)pos, (int)(pos+len), 
  451.                               expander, p0);
  452.         for (int i = text.offset + Math.min(index, text.count - 1); 
  453.          i >= text.offset; i--) {
  454.  
  455.         char ch = text.array[i];
  456.         if (Character.isWhitespace(ch)) {
  457.             // found whitespace, break here
  458.             index = i - text.offset + 1;
  459.             break;
  460.         }
  461.         }
  462.         int p1 = p0 + index;
  463.         LabelFragment frag = new LabelFragment(getElement(), p0, p1);
  464.         frag.x = (int) pos;
  465.         return frag;
  466.     }
  467.     return this;
  468.     }
  469.  
  470.     /**
  471.      * Creates a view that represents a portion of the element.
  472.      * This is potentially useful during formatting operations
  473.      * for taking measurements of fragments of the view.  If 
  474.      * the view doesn't support fragmenting (the default), it 
  475.      * should return itself.  
  476.      * <p>
  477.      * This view does support fragmenting.  It is implemented
  478.      * to return a nested class that shares state in this view 
  479.      * representing only a portion of the view.
  480.      *
  481.      * @param p0 the starting offset >= 0.  This should be a value
  482.      *   greater or equal to the element starting offset and
  483.      *   less than the element ending offset.
  484.      * @param p1 the ending offset > p0.  This should be a value
  485.      *   less than or equal to the elements end offset and
  486.      *   greater than the elements starting offset.
  487.      * @returns the view fragment, or itself if the view doesn't
  488.      *   support breaking into fragments.
  489.      * @see LabelView
  490.      */
  491.     public View createFragment(int p0, int p1) {
  492.     Element elem = getElement();
  493.     return new LabelFragment(elem, p0, p1);
  494.     }
  495.  
  496.     // --- variables ------------------------------------------------
  497.  
  498.     Font font;
  499.     FontMetrics metrics;
  500.     Color fg;
  501.     Segment text;
  502.     boolean underline;
  503.     boolean rightToLeft;
  504.  
  505.     /**
  506.      * how to expand tabs
  507.      */
  508.     TabExpander expander;
  509.  
  510.     /**
  511.      * location for determining tab expansion against.
  512.      */
  513.     int x;
  514.  
  515.     /**
  516.      * A label that represents only a portion of a character
  517.      * style run element.  This carries very little state
  518.      * of its own and depends heavily upon the outer class.
  519.      */
  520.     class LabelFragment extends View implements TabableView {
  521.  
  522.     /**
  523.      * Constructs a new view wrapped on an element.
  524.      *
  525.      * @param elem the element
  526.      * @param p0 the beginning of the range
  527.      * @param p1 the end of the range
  528.      */
  529.         public LabelFragment(Element elem, int p0, int p1) {
  530.         super(elem);
  531.         offset = (short) (p0 - elem.getStartOffset());
  532.         length = (short) (p1 - p0);
  533.     }
  534.  
  535.     // --- TabableView methods --------------------------------------
  536.  
  537.     /**
  538.      * Determines the desired span when using the given 
  539.      * tab expansion implementation.  
  540.      *
  541.      * @param x the position the view would be located
  542.      *  at for the purpose of tab expansion >= 0.
  543.      * @param e how to expand the tabs when encountered.
  544.      * @return the desired span >= 0
  545.      * @see TabableView#getTabbedSpan
  546.      */
  547.         public float getTabbedSpan(float x, TabExpander e) {
  548.         LabelView.this.expander = e;
  549.         this.x = (int) x;
  550.         return LabelView.this.getPreferredSpan(X_AXIS, getStartOffset(), 
  551.                            getEndOffset(), this.x);
  552.     }
  553.     
  554.     /**
  555.      * Determine the span along the same axis as tab 
  556.      * expansion for a portion of the view.  This is
  557.      * intended for use by the TabExpander for cases
  558.      * where the tab expansion involves aligning the
  559.      * portion of text that doesn't have whitespace 
  560.      * relative to the tab stop.  There is therefore
  561.      * an assumption that the range given does not
  562.      * contain tabs.
  563.      */
  564.         public float getPartialSpan(int p0, int p1) {
  565.         return LabelView.this.getPartialSpan(p0, p1);
  566.     }
  567.  
  568.     // --- View methods ----------------------------
  569.  
  570.     /**
  571.      * Fetches the portion of the model that this view is responsible for.
  572.      *
  573.      * @return the starting offset into the model
  574.      * @see View#getStartOffset
  575.      */
  576.         public int getStartOffset() {
  577.         Element e = getElement();
  578.         return e.getStartOffset() + offset;
  579.     }
  580.  
  581.     /**
  582.      * Fetches the portion of the model that this view is responsible for.
  583.      *
  584.      * @return the ending offset into the model
  585.      * @see View#getEndOffset
  586.      */
  587.         public int getEndOffset() {
  588.         Element e = getElement();
  589.         return e.getStartOffset() + offset + length;
  590.     }
  591.  
  592.     /**
  593.      * Renders a portion of a text style run.
  594.      *
  595.      * @param g the rendering surface to use
  596.      * @param a the allocated region to render into
  597.      */
  598.         public void paint(Graphics g, Shape a) {
  599.         paintText(g, a, getStartOffset(), getEndOffset(), true);
  600.     }
  601.  
  602.     /**
  603.      * Determines the preferred span for this view along an
  604.      * axis. 
  605.      *
  606.      * @param axis may be either X_AXIS or Y_AXIS
  607.      * @returns  the span the view would like to be rendered into.
  608.      *           Typically the view is told to render into the span
  609.      *           that is returned, although there is no guarantee.  
  610.      *           The parent may choose to resize or break the view.
  611.      */
  612.         public float getPreferredSpan(int axis) {
  613.         return LabelView.this.getPreferredSpan(axis, getStartOffset(), getEndOffset(), this.x);
  614.     }
  615.  
  616.     /**
  617.      * Determines the desired alignment for this view along an
  618.      * axis.  For the label, the alignment is along the font
  619.      * baseline for the y axis, and the superclasses alignment
  620.      * along the x axis.
  621.      *
  622.      * @param axis may be either X_AXIS or Y_AXIS
  623.      * @returns the desired alignment.  This should be a value
  624.      *   between 0.0 and 1.0 where 0 indicates alignment at the
  625.      *   origin and 1.0 indicates alignment to the full span
  626.      *   away from the origin.  An alignment of 0.5 would be the
  627.      *   center of the view.
  628.      */
  629.         public float getAlignment(int axis) {
  630.         return LabelView.this.getAlignment(axis);
  631.     }
  632.  
  633.  
  634.     /**
  635.      * Provides a mapping from the document model coordinate space
  636.      * to the coordinate space of the view mapped to it.
  637.      *
  638.      * @param pos the position to convert
  639.      * @param a the allocated region to render into
  640.      * @return the bounding box of the given position
  641.      * @exception BadLocationException  if the given position does not represent a
  642.      *   valid location in the associated document
  643.      * @see View#modelToView
  644.      */
  645.         public Shape modelToView(int pos, Shape a) throws BadLocationException {
  646.         return LabelView.this.modelToView(pos, a, getStartOffset(), getEndOffset());
  647.     }
  648.  
  649.     /**
  650.      * Provides a mapping from the view coordinate space to the logical
  651.      * coordinate space of the model.
  652.      *
  653.      * @param x the X coordinate
  654.      * @param y the Y coordinate
  655.      * @param a the allocated region to render into
  656.      * @return the location within the model that best represents the
  657.      *  given point of view
  658.      * @see View#viewToModel
  659.      */
  660.         public int viewToModel(float x, float y, Shape a) {
  661.         return LabelView.this.viewToModel(x, y, a, getStartOffset(), getEndOffset());
  662.     }
  663.  
  664.     /**
  665.      * Gives notification from the document that attributes were changed
  666.      * in a location that this view is responsible for.
  667.      *
  668.      * @param e the change information from the associated document
  669.      * @param a the current allocation of the view
  670.      * @param f the factory to use to rebuild if the view has children
  671.      * @see View#changedUpdate
  672.      */
  673.         public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
  674.         LabelView.this.changedUpdate(e, a, f);
  675.     }
  676.  
  677.     /**
  678.      * @see LabelView#getBreakWeight
  679.      */
  680.         public int getBreakWeight(int axis, float x, float len) {
  681.         return LabelView.this.getBreakWeight(axis, x, len, 
  682.                          getStartOffset(), getEndOffset());
  683.     }
  684.  
  685.     /**
  686.      * Breaks this view on the given axis at the given length.
  687.      *
  688.      * @param axis may be either X_AXIS or Y_AXIS
  689.      * @param offset the location in the model where the
  690.      *  fragment should start it's representation.
  691.      * @param pos the position along the axis that the
  692.      *  broken view would occupy.  This may be useful for
  693.      *  things like tab calculations.
  694.      * @param len specifies the distance along the axis
  695.      *  where a potential break is desired.  
  696.      * @param a the current allocation of the view
  697.      * @return the fragment of the view that represents the
  698.      *  given span, if the view can be broken.  If the view
  699.      *  doesn't support breaking behavior, the view itself is
  700.      *  returned.
  701.      * @see View#breakView
  702.      */
  703.         public View breakView(int axis, int offset, float pos, float len) {
  704.         return LabelView.this.breakView(axis, offset, pos, len);
  705.     }
  706.  
  707.     // ---- variables ---------------------------------
  708.     short offset;
  709.     short length;
  710.     int x;
  711.     }
  712. }
  713.  
  714.